//package erQiao.yfl.app.service.util.ThirdService;
//
//import javax.mail.Message;
//import javax.mail.Session;
//import javax.mail.Transport;
//import javax.mail.internet.InternetAddress;
//import javax.mail.internet.MimeMessage;
//import java.util.Properties;
//
//public class MailTask implements Runnable {
//
//    private String code;
//    private String email;
//    private int operation;
//
//    public MailTask(String code, String email, int operation) {
//        this.code = code;
//        this.email = email;
//        this.operation = operation;
//    }
//
//    @Override
//    public void run() {
//        System.out.println("开始发邮件...");
//        Properties prop = new Properties();
//        prop.put("mail.host", LoginConstants.MAIL_HOST);
//        prop.put("mail.transport.protocol", LoginConstants.MAIL_PROTOCOL);
//        prop.put("mail.smtp.auth", LoginConstants.MAIL_AUTH);
//        Session session = Session.getInstance(prop);
//        session.setDebug(true);
//        Transport ts = null;
//        try {
//            ts = session.getTransport();
//            ts.connect(LoginConstants.MAIL_USERNAME, LoginConstants.MAIL_PASSWORD);
//            Message message = new MimeMessage(session);
//            message.setFrom(new InternetAddress(LoginConstants.MAIL_USERNAME));
//            message.setRecipient(Message.RecipientType.TO, new InternetAddress(email));
//            StringBuilder sb  = new StringBuilder();
//            sb.append("<html><head></head><body>");
//            if (1 == operation) {//激活密码
//                sb.append("<a href="+LoginConstants.DOMAIN_NAME+"activate?code=");
//                sb.append(code);
//                sb.append(">点击激活</a></body>");
//                message.setSubject("点击激活");
//                message.setContent(sb.toString(), "text/html;charset=utf-8");
//            } else {//找回密码
//                sb.append("<a href="+LoginConstants.DOMAIN_NAME+"findPwd?code=");
//                sb.append(code);
//                sb.append(">点击激活</a></body>");
//                message.setSubject("找回密码");
//                message.setContent("这个test", "text/html;charset=utf-8");
//            }
//
//            ts.sendMessage(message, message.getAllRecipients());
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println("结束发邮件...");
//    }
//
//
//    // 创建Properties 类用于记录邮箱的一些属性
////        final Properties props = new Properties();
////        // 表示SMTP发送邮件，必须进行身份验证
////        props.put("mail.smtp.auth", LoginConstants.MAIL_AUTH);
////        //此处填写SMTP服务器
////        props.put("mail.smtp.host", LoginConstants.MAIL_HOST);
////        //端口号，QQ邮箱给出了两个端口，但是另一个我一直使用不了，所以就给出这一个587
////        props.put("mail.smtp.port", LoginConstants.MAIL_PORT);
////        // 此处填写你的账号
////        props.put("mail.user", LoginConstants.MAIL_USERNAME);
////        // 此处的密码就是前面说的16位STMP口令
////        props.put("mail.password", LoginConstants.MAIL_PASSWORD);
////
////        // 构建授权信息，用于进行SMTP进行身份验证
////        Authenticator authenticator = new Authenticator() {
////
////            protected PasswordAuthentication getPasswordAuthentication() {
////                // 用户名、密码
////                String userName = LoginConstants.MAIL_USERNAME;
////                String password = LoginConstants.MAIL_PASSWORD;
////                return new PasswordAuthentication(userName, password);
////            }
////        };
////        // 使用环境属性和授权信息，创建邮件会话
////        Session mailSession = Session.getInstance(props, authenticator);
////        // 创建邮件消息
////        MimeMessage message = new MimeMessage(mailSession);
////        // 设置发件人
////        InternetAddress form = null;
////        try {
////            form = new InternetAddress(LoginConstants.MAIL_USERNAME);
////            message.setFrom(form);
////
////            // 设置收件人的邮箱
////            InternetAddress to = new InternetAddress(email);
////            message.setRecipient(Message.RecipientType.TO, to);
////
////            // 设置邮件标题
////            message.setSubject("测试邮件");
////
////            // 设置邮件的内容体
////            StringBuilder sb = new StringBuilder();
////            sb.append("<html><head></head><body>");
////
////            if (operation == 1) {
////                sb.append("<a href=" + LoginConstants.DOMAIN_NAME + "activate.do?code=");
////                sb.append(code);
////                sb.append(">点击激活</a></body>");
////            } else {
////                sb.append("是否将您的密码修改为:");
////                sb.append(code.substring(0, 8));
////                sb.append("，<a href=" + LoginConstants.DOMAIN_NAME + "verify.do?code=" + code + ">");
////                sb.append("点击是</a></body>");
////            }
////            message.setContent(sb.toString(), "text/html;charset=UTF-8");
////
////            // 最后当然就是发送邮件啦
////            Transport.send(message);
////        } catch (Exception e) {
////            e.printStackTrace();
////        }
////    }
//}
//
//
//
//
//
//
//
//
